// Decompiled by DJ v2.3.3.38 Copyright 2000 Atanas Neshkov  Date: 03/11/2007 6:40:45
// Home Page : http//members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   ConfiguracionDao.java

package ig.formato.dao;

import ig.formato.dao.abs.DAO;
import ig.formato.dto.ConfiguracionDTO;
import ig.formato.util.IGFormatoException;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;

public class ConfiguracionDao extends DAO {

    public ConfiguracionDao() {
    }

    public Object buscar(Integer id) throws IGFormatoException {
        try {
            /*connectionIgFormato = */            getConnection();
            prep = connectionIgFormato.prepareStatement("SELECT ID, RELLENO, JUSTIFICADO, LONGITUD, OBJECT, SEPARADORDECIMAL, IDCAMPO, CLASSE,TRUNCAR FROM CONFIGURACION WHERE IDCAMPO = ?");
            prep.setInt(1, id.intValue());
            resul = prep.executeQuery();
            if (resul.next()) {
                return getDatos(resul, new ConfiguracionDTO());
            }
        } catch (ClassNotFoundException ex) {
            throw new IGFormatoException(ex);
        } catch (SQLException ex) {
            throw new IGFormatoException(ex);
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex);
        } finally {
            closeAll();
        }
        return null;
    }

    public Collection buscarTodos() throws IGFormatoException {
        Collection c = new ArrayList();
        try {
            /*connectionIgFormato = */            getConnection();
            prep = connectionIgFormato.prepareStatement("SELECT ID, RELLENO, JUSTIFICADO, LONGITUD, OBJECT, SEPARADORDECIMAL, IDCAMPO, CLASSE,TRUNCAR FROM CONFIGURACION");
            for (resul = prep.executeQuery(); resul.next();) {
                c.add(getDatos(resul, new ConfiguracionDTO()));
            }
            return c;
        } catch (ClassNotFoundException ex) {
            throw new IGFormatoException(ex, "No se pudo Cargar el Drive");
        } catch (SQLException ex) {
            throw new IGFormatoException(ex,"No se pudo cargar la lista de Configuracion de los campos del plano");
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex,"No se pudo cargar la lista de Configuracion de los campos del plano");
        } finally {
            closeAll();
        }
    }

    public Integer guardar(Object obj) throws IGFormatoException {
        ConfiguracionDTO dto = (ConfiguracionDTO) obj;
        try {
            /*connectionIgFormato = */            getConnection();
            if (dto.getId() == null) {
                prep = connectionIgFormato.prepareStatement("INSERT INTO CONFIGURACION(RELLENO, JUSTIFICADO, LONGITUD, OBJECT, SEPARADORDECIMAL, IDCAMPO,CLASSE,TRUNCAR, ID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
                dto.setId(getMaximoId("CONFIGURACION"));
            } else {
                prep = connectionIgFormato.prepareStatement("UPDATE CONFIGURACION SET RELLENO=?, JUSTIFICADO=?, LONGITUD=?, OBJECT=?, SEPARADORDECIMAL=?, IDCAMPO=?, CLASSE=?,TRUNCAR=?  WHERE ID=? ");
            }
            setDatos(prep, dto,"RELLENO, JUSTIFICADO, LONGITUD, OBJECT, SEPARADORDECIMAL, IDCAMPO, CLASSE,TRUNCAR, ID");
            prep.executeUpdate();
            return dto.getId();
        } catch (ClassNotFoundException ex) {
            throw new IGFormatoException(ex);
        } catch (SQLException ex) {
            throw new IGFormatoException(ex);
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex);
        } catch (Throwable ex) {
            throw new IGFormatoException(ex);            
        } finally {
            closeAll();
        }
    }

    public void eliminar(Integer id) throws IGFormatoException {
        try {
            /*connectionIgFormato = */            getConnection();
            prep = connectionIgFormato.prepareStatement("DELETE FROM CONFIGURACION WHERE IDCAMPO = ?");
            prep.setInt(1, id.intValue());
            prep.executeUpdate();
        } catch (SQLException ex) {
            throw new IGFormatoException(ex,"No se pudo eliminar la Configuracion de Campos del plano.");
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex,"No se pudo eliminar el Configuracion de Campos del plano.");
        } finally {
            closeAll();
        }
    }

    public Object existe(Object obj) throws IGFormatoException {
        Integer integer;
        try {
            /*connectionIgFormato = */            getConnection();
            prep = connectionIgFormato.prepareStatement("SELECT ID FROM CONFIGURACION WHERE CLASSE = ?");
            prep.setString(1, ((ConfiguracionDTO) obj).getClasse().trim());
            resul = prep.executeQuery();
            if (resul.next()) {
                return Integer.valueOf(resul.getInt("ID"));
            }
       } catch (SQLException ex) {
            throw new IGFormatoException(ex);
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex);
        } finally {
            closeAll();
        }
        return false;
    }
}
